home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Palettes / MiscClockPalette / MiscClockViewInspector.m < prev    next >
Encoding:
Text File  |  1995-07-06  |  2.4 KB  |  86 lines

  1. //
  2. //    MiscClockViewInspector.m -- a simple view class for displaying date/time
  3. //        Written by Scott Anguish Copyright (c) 1993 by Scott Anguish.
  4. //                Version 1.0.  All rights reserved.
  5. //
  6. //        This notice may not be removed from this source code.
  7. //
  8. //    This object is included in the MiscKit by permission from the author
  9. //    and its use is governed by the MiscKit license, found in the file
  10. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  11. //    for a list of all applicable permissions and restrictions.
  12. //    
  13.  
  14. #import "MiscClockViewInspector.h"
  15. #import <appkit/appkit.h>
  16. #import "MiscClockView.subproj/MiscClockView.h"
  17.  
  18. @implementation MiscClockViewInspector
  19.  
  20. - init
  21. {
  22.     char buf[MAXPATHLEN + 1];
  23.     id bundle;
  24.     
  25.     [super init];
  26.     bundle = [NXBundle bundleForClass:[MiscClockView class]];
  27.     [bundle getPath:buf forResource:"MiscClockViewInspector" ofType:"nib"];
  28.     [NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];
  29.     return self;
  30. }
  31.  
  32. - (BOOL)wantsButtons { return YES; }
  33.  
  34. - revert:sender
  35. {
  36.     // Put string in text object
  37.     [dayText setIntValue:[object weekday]];
  38.     [dateText setIntValue:[object date]];
  39.     [monthText setIntValue:[object month]];
  40.     [yearText setIntValue:[object year]];
  41.     [hourText setIntValue:[object hours]];
  42.     [minuteText setIntValue:[object minutes]];
  43.     [secondText setIntValue:[object seconds]];
  44.     [militaryTime setState:[object militaryTime]];
  45.     [showYear setState:[object showYear]];
  46.     [hiddenSwitch setState:[object isHidden]];
  47.  
  48.     return [super revert:sender];
  49. }
  50.  
  51. - ok:sender
  52. {
  53.     [object setMilitaryTime:[militaryTime state]];
  54.     [object setSeconds:[secondText intValue]];
  55.     [object setMinutes:[minuteText intValue]];
  56.     [object takeHoursFrom:hourText]; // to set the meridian right
  57.     [object setDate:[dateText intValue]];
  58.     [object setWeekday:[dayText intValue]];
  59.     [object setMonth:[monthText intValue]];
  60.     [object setYear:[yearText intValue]];
  61.     [object setShowYear:[showYear state]];
  62.     [object setHide:[hiddenSwitch state]];
  63.  
  64.     [object display];
  65.     return [super ok:sender];
  66. }
  67.  
  68. - setToCurrentTime:sender
  69. {
  70.     struct timeval tp;
  71.     struct timezone tzp;
  72.     struct tm *tv;
  73.     BOOL militaryTimeState;
  74.     
  75.     gettimeofday(&tp, &tzp);
  76.     tv = localtime(&tp.tv_sec);
  77.     [object setTime:tv];
  78.     [object display];
  79.     militaryTimeState = [militaryTime state];    // buffer militaryTime
  80.     [self revert:self]; // load values into the text fields
  81.     [militaryTime setState:militaryTimeState];    // redisoplay militaryTime
  82.     return [self ok:self]; // show change in the object
  83. }
  84.  
  85. @end
  86.